<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
 
// import Joomla modelitem library
jimport('joomla.application.component.modelitem');

class ShopModelOrder extends JModelItem
{

	function getCarts(){
		$db = JFactory::getDBO();
		$query = $db->getQuery(true);
		$id = JRequest::getInt('id');
		$session = JFactory::getSession();
		$list_cart = (array)$session->get('lightcart');
		if(array_key_exists($id,$list_cart))
		{
			$amount = $list_cart[$id]['quantity'] + 1;
			$list_cart[$id]['quantity'] = $amount;
			$session->set('lightcart',$list_cart);
		}
		else{
			$query->clear();
			$query->select('*');
			$query->from('#__shop_product');
			$query->where("id = $id");
			$db->setQuery((string)$query);
			$row = $db->loadObject();
			$list_cart[$id]['id'] = $row->id;
			$list_cart[$id]['title'] = $row->title;
			$list_cart[$id]['alias'] = $row->alias;
			$list_cart[$id]['price'] = $row->price;
			$list_cart[$id]['image'] = $row->image;
			$list_cart[$id]['quantity'] = 1;
			$list_cart[$id]['currency'] = $row->currency;
			
			unset($list_cart[0]);
			$session->set('lightcart',$list_cart);
		}
		return $list_cart;
	
	}

	
}